import { Inject, Controller, Get} from '@midwayjs/core';
import { Context } from '@midwayjs/koa';
import { UserService } from '../service/user.service';
import * as fs from 'fs';
import * as path from 'path';

@Controller('/api/user')
export class APIController {
      @Inject()
      ctx: Context;

    @Inject()
    userService: UserService;

    @Get('/announcement', { description: '获取公告栏' })
    async getannouncement(){
        const result = await this.userService.getannouncement()
                if(result.length!=0){
            for(var i = 0 ;i< result.length; i++){
              const fileName = result[i].image;
              const Annpic = fs.readFileSync(path.join(__dirname, '../../public/upload/conn', fileName));
              result[i]["src"] = Annpic     
            } 
          }
        return { success: true, message: '获取公告栏成功', result}
    }
}